<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理员页面</title>
<script>
    // 页面加载时检查是否注册成功
    window.onload = function() {
        <c:if test="${addUserSuccess}">
            alert('添加成功');
        </c:if>
    };
    </script>
<link href="${pageContext.request.contextPath}/static/css/allUser.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <h2>管理员页面</h2>
        <table border="1">
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>手机号</th>
                <th>密码</th>
                <th>身份</th>
                <th>短信</th>
                <th>流量</th>
                <th>通话</th>
                <th>余额</th>
                <th>套餐</th>
                <th>更新</th>
                <th>删除</th>
            </tr>
            <c:forEach items="${pageInfo.list}" var="user">
                <tr>
                    <td>${user.id}</td>
                    <td>${user.username}</td>
                    <td>${user.phone}</td>
                    <td>${user.password}</td>
                    <td>${user.role}</td>
                    <td>${user.sms}</td>
                    <td>${user.traffic}</td>
                    <td>${user.bill}</td>
                    <td>${user.balance}</td>
                    <td>${user.userpackage}</td>
                     <td>
                        <button class="update-btn"
                            onclick="window.location.href='${pageContext.request.contextPath }/toUpdateUser?id=${user.id}'">修改</button>
                    </td>
                    <td>
                        <button class="delete-btn"
                            onclick="if(confirm('确定删除该用户吗？')) window.location.href='${pageContext.request.contextPath }/deleteMulti?id=${user.id}&pageNum=${pageInfo.pageNum}'">删除</button>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <div class="pagination-and-buttons">
            <div>
                <p>总数据数: ${pageInfo.total}</p >
                <c:if test="${pageInfo.hasPreviousPage}">
                    <a href="${pageContext.request.contextPath}/getAllUsers?pageNum=${pageInfo.prePage}&pageSize=10">上一页</a>
                </c:if>
                <c:forEach begin="1" end="${pageInfo.pages}" var="page">
                    <a href="${pageContext.request.contextPath}/getAllUsers?pageNum=${page}&pageSize=10">${page}</a>
                </c:forEach>
                <c:if test="${pageInfo.hasNextPage}">
                    <a href="${pageContext.request.contextPath}/getAllUsers?pageNum=${pageInfo.nextPage}&pageSize=10">下一页</a>
                </c:if>
                <form action="${pageContext.request.contextPath}/getAllUsers" method="get">
                    <input type="number" name="pageNum" min="1" max="${pageInfo.pages}" placeholder="输入页码">
                    <input type="hidden" name="pageSize" value="10">
                    <input type="submit" value="跳转">
                </form>
            </div>
            <div>
                <button id="add-btn" onclick="window.location.href='${pageContext.request.contextPath }/toAddUser'">增加</button>
                <button id="exit-btn" onclick="window.location.href='${pageContext.request.contextPath}/index'">退出</button>
            </div>
        </div>
    </div>
</body>
</html>